﻿<template>
  <a-card :bordered="false">
    <div class="table-operator"></div>

    <div class="table-page-search-wrapper" style="text-align: right;">
      <a-input v-model="queryParam.keyword"  style="width: 20%" placeholder="请输入客户名称" />

      <a-button
        type="primary"
        icon="search"
        style="margin-left: 8px"
        @click="
          () => {
            this.pagination.current = 1
            this.getDataList()
          }
        "
      >
        搜索
      </a-button>

      <a-button icon="search" style="margin-left: 8px" @click="() =>{ 
        if(this.divistrue){ 
          this.divistrue = false
        }else{
          this.divistrue = true 
        }
        
        }">高级搜索</a-button>
      <a-button style="margin-left: 8px" icon="redo" @click="() => (queryParam = {})">重置</a-button>

      <a-button type="primary" style="margin-left: 8px;" v-if="hasPerm('accountrecharge.Add')" icon="plus" @click="hanldleAdd()">新建</a-button>
      <a-button
        v-if="hasPerm('accountrecharge.Delete')"
        type="danger"
        style="margin-left: 8px"
        icon="minus"
        @click="handleDelete(selectedRowKeys)"
        :disabled="!hasSelected()"
        :loading="loading"
        >删除</a-button
      >
      <a-button type="primary" icon="redo" style="margin-left: 8px" @click="getDataList()">刷新</a-button>
      

    <a-drawer
    :width="500"
    title="高级筛选"
    placement="top"
    :visible="divistrue"
    @close="onClose"
  >
    
    <a-row>
      <a-col :span="8">服务商名称&emsp;<a-input v-model="queryParam.serviceName" placeholder="请输入服务商名称" style="width:80%"></a-input></a-col>
        <a-col :span="8">单号&emsp;<a-input v-model="queryParam.signhao" style="width:80%" placeholder="请输入单号"></a-input></a-col>
        <!-- <a-col :span="8">充值时间&emsp;<a-date-picker style="width:80%" v-model="queryParam.Time" /></a-col> -->
        <a-col :span="8">客户名称&emsp;<a-input v-model="queryParam.keyword" style="width:80%" placeholder="请输入客户名称"></a-input></a-col>
    </a-row>
    <a-row style="margin-top:10px">
        <a-col :span="8">状&emsp;&emsp;&emsp;态&emsp;
          <a-select v-model="queryParam.Status" placeholder="请选择充值状态" style="width:80%">
            <a-select-option value="">全部数据</a-select-option>
            <a-select-option value="1">成功</a-select-option>
            <a-select-option value="0">失败</a-select-option>
          </a-select>
        </a-col>
        
    </a-row>
    
      <div style="text-align:right;margin-top:30px">
      <a-button  @click="onClose" icon="close">关闭</a-button>
      <a-button type="primary" style="margin-left:8px" icon="search" @click="() => {
            this.pagination.current = 1
            this.getDataList()
            this.divistrue=  false
          }">查询</a-button>
      </div>
  
  </a-drawer>
    </div>
    

    <a-table
      ref="table"
      style="margin-top:20px"
      :columns="columns"
      :rowKey="(row) => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="false"
      size="middle"
    >
      <template slot="Status" slot-scope="text">
        <span v-if="text == '1'"><a-tag color="green">正常</a-tag></span>
        <span v-if="text == '0'"><a-tag color="red">停用</a-tag></span>
      </template>
      <span slot="action" slot-scope="text, record">
        <template>
          <a v-if="hasPerm('accountrecharge.Edit')" @click="handleEdit(record.Id)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm
            title="确定删除吗？"
            v-if="hasPerm('accountrecharge.Delete')"
            ok-text="确定"
            cancel-text="取消"
            @confirm="handleDelete([record.Id])"
            @cancel="cancel"
          >
            <a href="#">删除</a>
          </a-popconfirm>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'

const columns = [
  { title: '业务单号', dataIndex: 'BusinessOrderNo', width: '10%' },
  { title: '企业名称', dataIndex: 'customerName', width: '10%' },
  { title: '服务商名称', dataIndex: 'ServiceProviderName', width: '10%' },
  { title: '服务商收款账号', dataIndex: 'ServiceAccountNo', width: '10%' },

  { title: '充值金额', dataIndex: 'RechargeAmount', width: '10%' },
  { title: '服务费计算规则', dataIndex: 'ruleType', width: '10%' },
  { title: '状态', dataIndex: 'RechargeStatus', width: '10%', scopedSlots: { customRender: 'Status' } },
  { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' } },
]
import { SearchOutlined } from '@ant-design/icons-vue'
export default {
  components: {
    EditForm,
    SearchOutlined,
  },
  mounted() {
    this.getDataList()
  },
  data() {
    return {
      divistrue:false,
      divheight:'0px',
      data: [],
      pagination: {
        current: 1,
        pageSize: 10,
        showSizeChanger: true,
        showQuickJumper: true,
        total: 0, // 总数，必须先有
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        onShowSizeChange: (current, pageSize) => {
          this.pagination.current = 1
          this.pagination.pageSize = pageSize
          this.getDataList() //显示列表的接口名称
        },
        // 改变每页数量时更新显示
        onChange: (current, size) => {
          this.pagination.current = current
          this.pagination.pageSize = size
          this.getDataList()
        },
      },
      filters: {},
      sorter: { field: 'Id', order: 'asc' },
      loading: false,
      columns,
      queryParam: {},
      selectedRowKeys: [],
    }
  },
  methods: {
    onClose(){
      this.divistrue = false
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/Base_leasesystem_accountrecharge/leasesystem_accountrecharge/GetHeightSearch', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
          ...this.filters,
        })
        .then((resJson) => {
          console.log(resJson)
          this.loading = false
          this.data = resJson.Data.Data
          const pagination = { ...this.pagination }
          pagination.total = resJson.Data.Total
          this.pagination = pagination
        })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    hanldleAdd() {
      this.$refs.editForm.openForm()
    },
    handleEdit(id) {
      this.$refs.editForm.openForm(id)
    },
    handleDelete(ids) {
      var thisObj = this

      return new Promise((resolve, reject) => {
        thisObj.$http
          .post('/Base_leasesystem_accountrecharge/leasesystem_accountrecharge/DeleteData', ids)
          .then((resJson) => {
            resolve()

            if (resJson.Success) {
              thisObj.$message.success('操作成功!')

              thisObj.getDataList()
            } else {
              thisObj.$message.error(resJson.Msg)
            }
          })
      })
    },
    cancel(e) {
      this.$message.error('已取消删除')
    },
  },
}
</script>

<style>
.ant-table-thead > tr > th {
  font-weight: 600;
  color: #333333;
}
</style>